﻿<UserControl x:Class="YATE.FontPicker"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:YATE"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             Height="26"
             HorizontalAlignment="Center"
             VerticalAlignment="Center"
             Padding="1,0"
             mc:Ignorable="d">
    <ComboBox xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
              x:Name="cb_Combo"
              IsEditable="True"
              ItemTemplate="{DynamicResource FontTemplate}"
              SelectionChanged="ComboBox_SelectionChanged">
        <ComboBox.Resources>
            <CollectionViewSource x:Key="myFonts" Source="{Binding Source={x:Static Fonts.SystemFontFamilies}}">
                <CollectionViewSource.SortDescriptions>
                    <ComponentModel:SortDescription PropertyName="Source" />
                </CollectionViewSource.SortDescriptions>
            </CollectionViewSource>

            <Style x:Key="FontStyle">
                <Setter Property="Control.FontFamily" Value="{Binding Source}" />
                <Setter Property="Control.FontSize" Value="12" />
            </Style>

            <DataTemplate x:Key="FontTemplate">
                <StackPanel VirtualizingStackPanel.IsVirtualizing="True">
                    <TextBlock Style="{StaticResource FontStyle}"
                               Text="{Binding Source}"
                               ToolTip="{Binding Source}" />
                </StackPanel>
            </DataTemplate>

        </ComboBox.Resources>

        <ComboBox.ItemsSource>
            <Binding Source="{StaticResource myFonts}" />
        </ComboBox.ItemsSource>
    </ComboBox>
</UserControl>
